package com.zhihaoliang.coroutine.buss.channel

import com.zhihaoliang.coroutine.buss.channel.func.*
import com.zhihaoliang.coroutine.common.list.ListActivity
import com.zhihaoliang.coroutine.common.list.ListItem

/**
 * @author 支豪亮
 * @date 2022/10/27 16:09
 * @des 通道
 */
class ChannelActivity : ListActivity() {
    override val listItem: List<ListItem> = listOf(
        ListItem("Building channel producers", 0),
        ListItem("Pipelines", 1),
        ListItem("Prime numbers with pipeline", 2),
        ListItem("Fan-out", 3),
        ListItem("Fan-in", 4),
        ListItem("Buffered channels", 5),
        ListItem("Channels are fair", 6),
        ListItem("Ticker channels", 7),
    )

    override fun onItemClick(item: ListItem) {
        when (item.index) {
            1 -> ChannelPipeline.onPipeline(mainScope)
            2 -> PrimeFinder.findPrime(mainScope)
            3 -> OutFan.fanOut(mainScope)
            4 -> InFan.fanIn(mainScope)
            5 -> ChannelBuffer.sendWithBuffer(mainScope)
            6 -> ChannelFair.showChannelFair(mainScope)
            7 -> TickerChannel.tickerSend(mainScope)
            else -> ChannelProducer.onProducer(mainScope)
        }
    }

}
